import { reactive } from "vue"


export const dialogList= reactive([])
const cacheDialog = reactive([])
let router = null
export const init = (data) => {
  router = data
}

export const addDialog = (options) => {
  dialogList.push(Object.assign(options, { visible: true, pathKey: router.currentRoute.value.path, show: true }))
}

export const closeDialog = (item, i, args, isNativeClose) => {
  item.visible = false
  cacheDialog.push(i)
  if (!isNativeClose) item.callBack && item.callBack(...args)
  setTimeout(() => {
    // 加上动效并延时清除缓存
    while (cacheDialog?.length) {
      const index = cacheDialog.shift()
      if (index === undefined) break
      dialogList.splice(index, 1)
    }
  }, 500)
}
